//
//  ProjectInfoViewController.m
//  BigToBig
//
//  Created by 毛丽媛 on 16/7/8.
//  Copyright © 2016年 cn.cloudtp. All rights reserved.
//

#import "ProjectInfoViewController.h"
#import "SKSTableView.h"
#import "SKSTableViewCell.h"

@interface ProjectInfoViewController ()
<
    UITableViewDelegate,
    UITableViewDataSource,
    SKSTableViewDelegate
>
@property(nonatomic,strong)NSArray *sectionArr;
@property(nonatomic,strong)NSArray *createProArr;
@property(nonatomic,strong)NSArray *detailArr;
@property(nonatomic,strong)NSArray *myInfoArr;
@property(nonatomic,strong)NSArray *teamInfoArr;
@property(nonatomic,strong)NSArray *groDateArr;
@property(nonatomic,strong)NSArray *lastArr;
@property(nonatomic,strong)NSDictionary *dataDic;
@property (nonatomic, assign) BOOL isExpanded;
@property(nonatomic,strong)NSMutableDictionary *showDic;
@property(nonatomic,strong)NSMutableArray *openSectionArr;
@property (nonatomic , strong)SKSTableView *sksTableView;

@property (nonatomic , strong)NSArray *contents;

@end

@implementation ProjectInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
    titleLab.text = @"项目信息";
    titleLab.textColor = [UIColor whiteColor];
    [self setBackBar];
    titleLab.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLab;
    
    self.navigationController.navigationBar.translucent = NO;

    self.navigationController.navigationBar.barTintColor = COLOR_RGBA(77, 155, 255, 1);
    
    self.sksTableView = [[SKSTableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    self.sksTableView.backgroundColor = COLOR_RGBA(247, 247, 247, 1);
    self.sksTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _sksTableView.SKSTableViewDelegate = self;
    self.tableView = self.sksTableView;
    self.tableView.rowHeight = 60;
    self.tableView.showsVerticalScrollIndicator = NO;
   
    
    [self initDataSource];
    
    CGRect frame = self.view.frame;
    frame.origin.y = 20;
    frame.size.height = frame.size.height - 20;

}

#pragma mark tableView点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
 #pragma mark 返回section个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//    return _sectionArr.count;
    return self.contents.count;
}
#pragma mark 返回分区行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
//        if (section == 0) {
//            return self.createProArr.count;
//        }else if (section == 1) {
//            return self.detailArr.count;
//        }else if (section == 2) {
//            return _myInfoArr.count;
//        }else if (section == 3) {
//            return _teamInfoArr.count;
//        }else if (section == 4) {
//            return _groDateArr.count;
//        }else if (section == 5) {
//            return _lastArr.count;
//        }else{
//            return _sectionArr.count;
//        }
  
    return [self.contents[section] count];

}
- (NSInteger)tableView:(SKSTableView *)tableView numberOfSubRowsAtIndexPath:(NSIndexPath *)indexPath
{
    return [self.contents[indexPath.section][indexPath.row] count] - 1;
}

#pragma mark 分区高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50;
}

#pragma mark 绘制cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *CellIdentifier = @"SKSTableViewCell";
    
    SKSTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (!cell)
        cell = [[SKSTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    
    cell.textLabel.text = self.contents[indexPath.section][indexPath.row][0];
    
    if (indexPath.section == 5) {
        cell.isExpandable = NO;
    }
    else{
        cell.isExpandable = YES;
    }
    
    return cell;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForSubRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *str = _sectionArr[indexPath.section];
    NSArray *arr = [_dataDic objectForKey:str];
    NSDictionary *sectionDic = [arr objectAtIndex:indexPath.subRow - 1];
    static NSString *CellIdentifier = @"cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.contentView.backgroundColor = [UIColor whiteColor];
    cell = nil;
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    UILabel *userLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 10, kScreenWidth, 40)];
    userLabel.text = [sectionDic valueForKey:@"name"];
    [cell.contentView addSubview:userLabel];

    UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth / 2 - 20, 0, kScreenWidth / 2 - 10, 60)];
    contentLabel.text = [sectionDic valueForKey:@"content"];
    contentLabel.textAlignment = NSTextAlignmentRight;
    contentLabel.font = [UIFont systemFontOfSize:15];
    contentLabel.textColor = [UIColor colorWithWhite:0.827 alpha:1.000];
    [cell.contentView addSubview:contentLabel];

    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

#pragma mark 返回
- (void)backController:(UIButton*)btn{
    [self.navigationController popViewControllerAnimated:YES];
}


-(void)initDataSource{
    self.contents = [NSArray array];
    self.sectionArr = [[NSArray alloc] initWithObjects:@"创建的项目",@"详情描述",@"我的信息",@"团队信息",@"成长数据",@" ", nil];
    
    NSDictionary *dic01=[[NSDictionary alloc]initWithObjectsAndKeys:@"项目标志",@"name",@"点击上传",@"content", nil];
    NSDictionary *dic02=[[NSDictionary alloc]initWithObjectsAndKeys:@"项目名称",@"name",@"给您的项目起个名字",@"content", nil];
    NSDictionary *dic03=[[NSDictionary alloc]initWithObjectsAndKeys:@"项目梗概",@"name",@"用一句话介绍项目",@"content", nil];
    NSDictionary *dic04=[[NSDictionary alloc]initWithObjectsAndKeys:@"项目介绍",@"name",@"简单的介绍一下你的",@"content", nil];
    NSDictionary *dic05=[[NSDictionary alloc]initWithObjectsAndKeys:@"所属领域",@"name",@"选一下包含领域",@"content", nil];
    self.createProArr = [[NSArray alloc]initWithObjects:dic01,dic02,dic03,dic04,dic05,nil];
    
    NSDictionary *dic11=[[NSDictionary alloc]initWithObjectsAndKeys:@"市场调研",@"name",@"",@"content", nil];
    NSDictionary *dic12=[[NSDictionary alloc]initWithObjectsAndKeys:@"竞争优势",@"name",@"",@"content", nil];
    NSDictionary *dic13=[[NSDictionary alloc]initWithObjectsAndKeys:@"商业模式",@"name",@"",@"content", nil];
    
    self.detailArr = [[NSArray alloc]initWithObjects:dic11,dic12,dic13, nil];
    
    NSDictionary *dic21=[[NSDictionary alloc]initWithObjectsAndKeys:@"创建者姓名",@"name",@"",@"content",nil];
    NSDictionary *dic22=[[NSDictionary alloc]initWithObjectsAndKeys:@"项目中职位",@"name",@"",@"content", nil];
    NSDictionary *dic23=[[NSDictionary alloc]initWithObjectsAndKeys:@"常用邮箱",@"name",@"",@"content", nil];
    
    self.myInfoArr = [[NSArray alloc]initWithObjects:dic21,dic22,dic23, nil];
    
    
    NSDictionary *dic31=[[NSDictionary alloc]initWithObjectsAndKeys:@"头像",@"name",@"点击上传",@"content", nil];
    NSDictionary *dic32=[[NSDictionary alloc]initWithObjectsAndKeys:@"姓名",@"name",@"",@"content", nil];
    NSDictionary *dic33=[[NSDictionary alloc]initWithObjectsAndKeys:@"职位",@"name",@"",@"content", nil];
    NSDictionary *dic34=[[NSDictionary alloc]initWithObjectsAndKeys:@"成员邮箱",@"name",@"",@"content", nil];
    NSDictionary *dic35=[[NSDictionary alloc]initWithObjectsAndKeys:@"成员简介",@"name",@"",@"content", nil];
    NSDictionary *dic36=[[NSDictionary alloc]initWithObjectsAndKeys:@"团队优势",@"name",@"",@"content", nil];
    
    self.teamInfoArr = [[NSArray alloc]initWithObjects:dic31,dic32,dic33,dic34,dic35,dic36, nil];
    
    NSDictionary *dic41=[[NSDictionary alloc]initWithObjectsAndKeys:@"下载量",@"name",@"",@"content", nil];
    
    self.groDateArr = [[NSArray alloc]initWithObjects:dic41, nil];
    
    NSDictionary *dic51=[[NSDictionary alloc]initWithObjectsAndKeys:@"项目大事记",@"name",@"",@"content", nil];
    
    self.contents = @[@[@[@"创建的项目",dic01,dic02,dic03,dic04,dic05]],
                      @[@[@"详情描述",dic11,dic12,dic13]],
                      @[@[@"我的信息",dic21,dic22,dic23]],
                      @[@[@"团队信息",dic31,dic32,dic33,dic34,dic35,dic36]],
                      @[@[@"成长数据",dic41]],
                      @[@[@"项目大事记"]]];
    _lastArr = [[NSArray alloc]initWithObjects:dic51, nil];
    
    _dataDic = [[NSDictionary alloc]initWithObjectsAndKeys:_createProArr,[_sectionArr objectAtIndex:0],_detailArr,[_sectionArr objectAtIndex:1],_myInfoArr,[_sectionArr objectAtIndex:2],_teamInfoArr,[_sectionArr objectAtIndex:3],_groDateArr,[_sectionArr objectAtIndex:4], _lastArr,[_sectionArr objectAtIndex:5],nil];
    
}
#pragma mark 导航栏左右Button
- (void)setBackBar{
    
    BackButton *backBtn=[BackButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 44, 44);
    [backBtn addTarget:self action:@selector(backController:) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn.imageView setContentMode:UIViewContentModeLeft];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
    
    BackButton *saveBtn=[BackButton buttonWithType:UIButtonTypeCustom];
    saveBtn.frame = CGRectMake(kScreenWidth - 44,0 , 44, 44);
    [saveBtn addTarget:self action:@selector(SaveMessage) forControlEvents:UIControlEventTouchUpInside];
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [saveBtn.imageView setContentMode:UIViewContentModeLeft];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:saveBtn];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
}

#pragma mark 保存
- (void)SaveMessage{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"继续完善内容" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        [self.navigationController dismissViewControllerAnimated:alert completion:nil];
    }];
    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        FinancingRZTableViewController *finaVC = [[FinancingRZTableViewController alloc] init];
        [self.navigationController pushViewController:finaVC animated:YES];
    }];
    
    [alert addAction:cancel];
    [alert addAction:ok];
    [self.navigationController
     presentViewController:alert animated:YES completion:nil];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
